<?php
namespace Modules\Activity\Entities\Jika;

use Modules\Activity\Entities\BaseActivityModel;
use Illuminate\Database\Eloquent\Builder;
use Modules\Order\Traits\Skuable;

use ThrowException;

// 集卡
class Activity extends BaseActivityModel
{
    use Skuable;

    protected $table = 'jika_activity';

    public $activityType = 'jika';
    public $activityTypeText = '集卡';

    // protected $guarded = ['union_status', 'union_status_text', 'type_text'];

    // protected $appends = ['union_status', 'union_status_text'];

    protected $casts = [
        'page' => 'json'
    ];

    public function getType($type) 
    {
        $map = [
            'base_sku_type' => 'jika',
            'node_type' => 'jika'
        ];

        return @$map[$type];
    }

    // 
    public function getNodeEntity()
    {
        return $this;
    }

    // 所有sku
    public function skus()
    {
        return $this->hasMany('\Modules\Activity\Entities\Jika\Sku', 'activity_id')->orderBy('list_weight', 'desc')->orderBy('id', 'asc');
    }

    // 所有sku
    public function tasks()
    {
        return $this->hasMany('\Modules\Activity\Entities\Jika\Task', 'activity_id')->orderBy('list_weight', 'desc')->orderBy('id', 'asc');
    }

}
